package spring.boot.fastdep.jwt.config;

import com.louislivi.fastdep.shirojwt.shiro.FastDepShiroJwtAuthorization;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import spring.boot.fastdep.jwt.service.TUserService;

import java.util.Set;

@Slf4j
@Configuration
public class FastDepShiroJwtConfig extends FastDepShiroJwtAuthorization {

    @Autowired
    private TUserService tUserService;

    @Override
    public SimpleAuthorizationInfo getAuthorizationInfo(String userId) {
        log.info("当前登录用户id={}", userId);
        Set<String> permissions = tUserService.selectPermissionsByUserId(Long.parseLong(userId));
        SimpleAuthorizationInfo simpleAuthorizationInfo = new SimpleAuthorizationInfo();
        simpleAuthorizationInfo.addStringPermissions(permissions);
        return simpleAuthorizationInfo;
    }
}
